<template>
  <ul>
    <li v-for="item in comments" :key="item.id">
      <b>{{ item.content }} &nbsp;</b>
      <button @click="del(item.id)">删除</button>
    </li>
  </ul>
</template>
<script>
import * as api from "@/api/comment";
import { mapState, mapActions } from "vuex";
export default {
  methods: {
    ...mapActions("comment", ["FETCH_COMMENT"]),
    async del(id) {
      let res = await api.delComment(id);
      if (res.data.state) {
        this.FETCH_COMMENT();
      }
    },
  },
  computed: {
    ...mapState("comment", ["comments"]),
  },
  created() {
    this.FETCH_COMMENT();
  },
};
</script>
